package com.zd.commodity.productMng.action;

import java.sql.Timestamp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zd.commodity.action.BaseAction;
import com.zd.commodity.productMng.biz.IProductAttrGroupBiz;
import com.zd.commodity.productMng.entity.ProductAttrGroup;
import com.zd.commodity.userMng.entity.User;
@Scope("prototype")
@Controller("productAttrGroupAction")
public class ProductAttrGroupAction extends BaseAction<ProductAttrGroup> {
	private IProductAttrGroupBiz productAttrGroupBiz;
	//添加属性组
	public void addAttrGroup(){
		ProductAttrGroup productAttrGroup = super.getT();
		User user = (User)request.getSession().getAttribute("user");
		productAttrGroup.setCreator(user.getId());
		productAttrGroup.setCreationTime(new Timestamp(System.currentTimeMillis()));
		try {
			productAttrGroupBiz.add(productAttrGroup);
			write(ajaxReturn(true, "添加成功！", null));
		} catch (Exception e) {
			write(ajaxReturn(false, "添加失败！", null));
			e.printStackTrace();
		}
	}
	//修改属性组
	public void updateAttrGroup(){
		ProductAttrGroup productAttrGroup = super.getT();
		User user = (User)request.getSession().getAttribute("user");
		ProductAttrGroup productAttrGroup2 = productAttrGroupBiz.get(productAttrGroup.getId());
		productAttrGroup2.setUpdater(user.getId());
		productAttrGroup2.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		productAttrGroup2.setName(productAttrGroup.getName());
		try {
			productAttrGroupBiz.update(productAttrGroup2);
			write(ajaxReturn(true, "修改成功！", null));
		} catch (Exception e) {
			write(ajaxReturn(false, "修改失败！", null));
			e.printStackTrace();
		}
	}
	//跳转到显示框架的jsp
	public String toShowChooseGroupFrame(){
		return "showFrame";
	}
	public IProductAttrGroupBiz getProductAttrGroupBiz() {
		return productAttrGroupBiz;
	}
	@Autowired
	public void setProductAttrGroupBiz(IProductAttrGroupBiz productAttrGroupBiz) {
		this.setBaseBiz(productAttrGroupBiz);
		this.productAttrGroupBiz = productAttrGroupBiz;
	}
}
